#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    long long t,n;
    int maxx=-1;
    cin>>t;
    long long ans[t];
    int a[1000000];
    for(int i=0;i<=t-1;i++)
    {
        ans[i]=0;
        memset(a,0,sizeof(a));
        cin>>n;
        int b[n];
        for(int j=0;j<=n-1;j++)
        {
            cin>>b[j];
            maxx=max(maxx,b[j]);
        }
        for(int j=0;j<=n-1;j++)
        {
            a[b[j]]++;
        }
        for(int j=0;j<=maxx;j++)
        {
            if(a[j]>1)
            {
                ans[i]=ans[i]+((a[j]-1)*j);
            }
        }
    }
    for(int i=0;i<=t-1;i++)
    {
        cout<<ans[i]<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
